package com._4pd.demo.formal.watcher;

import com._4pd.demo.formal.K8sClient;
import io.fabric8.kubernetes.client.Watcher;

public abstract class StatusWatcher<T> implements Watcher<T> {
    protected K8sClient client;
    public StatusWatcher (K8sClient client){
        this.client = client;
    }
    @Override
    public void eventReceived(Action action, T resource) {
        try {
            switch (action) {
                case ADDED:
                    AddedAction(resource);
                    break;
                case BOOKMARK:
                    BookmarkAction(resource);
                    break;
                case MODIFIED:
                    ModifiedAction(resource);
                    break;
                case DELETED:
                    DeletedAction(resource);
                    break;
                case ERROR:
                    ErrorAction(resource);
                    break;
                default:
                    throw new RuntimeException("error action type " + action);
            }
        }catch (Exception e){
            e.printStackTrace();
            throw e;
        }
    }

    abstract void AddedAction(T resource);
    abstract void ModifiedAction(T resource);
    abstract void DeletedAction(T resource);
    abstract void ErrorAction(T resource);
    abstract void BookmarkAction(T resource);
}
